package com.sy.controller;

import com.sy.bean.Supplier;
import com.sy.bean.management.SupplierQuery;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.BindingResultUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/set")
@Api(tags = "供应商管理")
public class SupplierController extends BaseController {
    @Autowired
    SupplierService supplierService;
    @PostMapping("/supplier/list")
    @ApiOperation("供应商列表")
    public ResultBean<PageBean> query(@RequestBody SupplierQuery query){
        PageBean bean = supplierService.query(BeanOfMap.bom(query));
        return success("供应商列表",bean);
    }
    @PostMapping("/supplier/save")
    @ApiOperation("保存供应商")
    public ResultBean save(@RequestBody @Validated Supplier supplier, BindingResult result){
        validate(result);
        if (supplier.getEid()==0)
            return gotoResult(0,"企业id不能为空,保存");
        int save = supplierService.save(supplier);
        return gotoResult(save,"保存");
    }
    @PostMapping("/supplier/exportSup")
    @ApiOperation("导出供应商列表")
    public ResultBean exportSup(@RequestBody Map map){
        String url = supplierService.exportSup(map);
        return success("导出供应商列表",url);
    }
}
